//
//  HMAccountTool.m
//  Gegeda_music_MY
//
//  Created by lanou3g on 15/11/5.
//  Copyright © 2015年 周莹. All rights reserved.
//

#import "HMAccountTool.h"
#import "HMAccount.h"
@implementation HMAccountTool



+(void)save:(HMAccount *)account{

//归档

    NSString *doucumtPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
    doucumtPath = [doucumtPath  stringByAppendingString:@"/account.data"];
    [NSKeyedArchiver  archiveRootObject:account toFile:doucumtPath];
  
}
+(HMAccount *)account{
//读取账号
    NSString *doucumtPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
    doucumtPath = [doucumtPath  stringByAppendingString:@"/account.data"];
    HMAccount *account = [NSKeyedUnarchiver  unarchiveObjectWithFile:doucumtPath];
//判断账号是否已经过期
    NSDate *now  = [NSDate  date];
    /**
     NSOrderedAscending = -1L,  升序，越往右边越大
     NSOrderedSame, 相等，一样
     NSOrderedDescending 降序，越往右边越小
     */
    if ([now  compare:account.expires_time]!= NSOrderedAscending) {
        //过期
        
        account = nil;
    }
    return account;


}


@end
